<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <title>购物车全选</title>
</head>
<style>
    * {
        padding: 0;
        margin: 0;
    }
    
    .wrap {
        width: 300px;
        margin: 100px auto 0;
    }
    
    table {
        border-collapse: collapse;
        border-spacing: 0;
        border: 1px solid #c0c0c0;
        width: 300px;
    }
    
    th,
    td {
        border: 1px solid #d0d0d0;
        color: #404060;
        padding: 10px;
    }
    
    th {
        background-color: #09c;
        font: bold 16px "微软雅黑";
        color: #fff;
    }
    
    td {
        font: 14px "微软雅黑";
    }
    
    tbody tr {
        background-color: #f0f0f0;
    }
    
    tbody tr:hover {
        cursor: pointer;
        background-color: #fafafa;
    }
    
    #add {
        float: right;
        width: 40px;
        height: 20px;
    }
    
    #del {
        float: right;
        width: 40px;
        height: 20px;
    }
</style>

<body>

    <div class="wrap">

        <div>商品名称：<input type="text" id="name"><button id="add">添加</button></div>
        <div>商品价格：<input type="text" id="price"></div>


        <table>
            <thead>
                <tr>
                    <th>
                        <input type="checkbox" id="j_cbAll" />
                    </th>
                    <th>商品</th>
                    <th>价钱</th>
                    <th><input type="button" value="删除选中" class="rmAll"></th>
                </tr>
            </thead>

            <tbody id="j_tb">
                <tr class="tr">
                    <td>
                        <input type="checkbox" class="check" />
                    </td>
                    <td>iPhone8</td>
                    <td>8000</td>
                    <td><input type="button" value="删除" class="remove"></td>
                </tr>
                <tr>
                    <td>
                        <input type="checkbox" class="check" />
                    </td>
                    <td>iPad Pro</td>
                    <td>5000</td>
                    <td><input type="button" value="删除" class="remove"></td>
                </tr>
                <tr class="tr">
                    <td>
                        <input type="checkbox" class="check" />
                    </td>
                    <td>iPad Air</td>
                    <td>2000</td>
                    <td><input type="button" value="删除" class="remove"></td>
                </tr>
                <tr class="tr">
                    <td>
                        <input type="checkbox" class="check" />
                    </td>
                    <td>Apple Watch</td>
                    <td>2000</td>
                    <td><input type="button" value="删除" class="remove"></td>
                </tr>
            </tbody>
        </table>
    </div>

</body>
<script src="../../../jquery-3.3.1.min.js"></script>
<script>
    $("#j_cbAll").on("click", function() {
        $("input").prop("checked", $("#j_cbAll").prop("checked"));
    })
    $("#add").on("click", function() {
        var name = $("#name").val();
        var price = $("#price").val();
        $("table").append("<tr class='tr'><td><input type='checkbox' class='check'/></td><td>" + name + "</td><td>" + price + "</td><td ><input type='button' value='删除' class='remove'></td></tr>")
    })

    $("table").on("click", ".remove", function() {
        if (confirm("请确认是否删除")) {
            $(this).parent().parent().remove();
        }
    })
    $("table").on("click", ".rmAll", function() {
        if (confirm("请确认是否删除")) {
            $(".check:checked").parent().parent().remove();
        }

    })
</script>

</html>